<?php
/**
 * Created by PhpStorm.
 * User: dreamy
 * Date: 2022-04-21
 * Time: 12:14
 */
namespace common\services;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * Class DomainExtraConfigService
 *
 * @package common\services
 */
class DomainExtraConfigService extends  BaseService
{
    public static $domainConf = [];

    public static $needAuthDomainAlias = ['cwgj','qyfw','qyy']; // 需要执行授权码检测的域名别名

    /**
     * 根据域名生成当前配置
     * @return mixed
     */
    public static function getConfig()
    {
        $host = Yii::$app->request->hostName;
        $domainExtraConfig = Yii::$app->params['domainExtraConfig'];
        $currentConfig = $domainExtraConfig['default'];
        foreach ($domainExtraConfig as $domainKey => $domainItem){
            if($domainItem['host'] == $host) {
                $currentConfig = $domainItem;
                break;
            }
        }
        self::$domainConf = $currentConfig;
        return $currentConfig;
    }

    /**
     * 获取当前域名配置下的某一项具体的值 如 name | logo
     * @param $key
     *
     * @return mixed
     */
    public static function getVal($key)
    {
        if(empty(self::$domainConf)) {
            self::getConfig();
        }

        return ArrayHelper::getValue(self::$domainConf,$key,'');
    }
}
